//
//  web2ViewController.m
//  iosweb
//
//  Created by 廉英雷 on 15/11/16.
//  Copyright © 2015年 廉英雷. All rights reserved.
//

#import "web2ViewController.h"

@interface web2ViewController ()<UIWebViewDelegate>

@property(nonatomic,weak) UIWebView *webView;
@end

@implementation web2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
      UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.bounds];
      [self.view addSubview:web];
      NSString *path = @"http://app.zhpgo.com/QuickService/share/product/product.jsp?coupon=15070000050&from=groupmessage&isappinstalled=0";
      NSURLRequest *requeat = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:path]];
      [web loadRequest:requeat];
      web.delegate = self;
     // web.detectsPhoneNumbers = YES;
      self.webView = web;
      web.pageLength = 10;
      //css文件的类型
      
      web.paginationBreakingMode = UIWebPaginationBreakingModePage;
     
      UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
      btn.backgroundColor = [UIColor whiteColor];
      [btn setTitle:@"返回" forState:UIControlStateNormal];
      [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
      UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithCustomView:btn];
      self.navigationItem.leftBarButtonItem = bar;
      
}
- (void)btnClick{
      
      [self.webView goBack];

}

- (void)webViewDidFinishLoad:(UIWebView *)webViewE{
      
      [webViewE stringByEvaluatingJavaScriptFromString:@"toShopping('')"];
      [webViewE stringByEvaluatingJavaScriptFromString:@"couponCode"];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    //  <div onclick="toShopping('')">go shopping</div>
}

- (void)couponCode{

      [self showTipView:@"点击了正品优惠码"];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
      BOOL isOpen = YES;
      
      NSLog(@"----%@",request.URL.absoluteString);
      NSLog(@"schea----%@",request.URL.scheme);
      if ([request.URL.scheme isEqualToString:@"tel"]) {
            NSLog(@"点击电话客服");
            [self showTipView:@"点击电话客服"];
      }
      
           return isOpen;
}

@end
